package com.example.controller;

import com.example.pojo.Indent;
import com.example.pojo.Result;
import com.example.service.impl.IndentServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.List;
@Slf4j
@CrossOrigin
@RequestMapping("/indent")
@RestController
public class IndentController {
    @Autowired
    private IndentServiceImpl indentService;

    @Autowired
    private HttpServletRequest request;

    //下单支付成功添加到订单
    @PostMapping
    public Result addOrder(@RequestBody Indent indent){
        log.info("{}",indent.getIdA());
        if(indent.getY()==null){
            return Result.error("请选择租赁时间");
        }
        indentService.addOrder(indent,request);
        return Result.success();
    }

    //租客显示个人房源
    @GetMapping
    public Result getOrder(String name, LocalDateTime date){
        List<Indent> list=indentService.getOrder(name,date,request);
        return Result.success(list);
    }

    //租客删除个人房源
    @DeleteMapping("/{id}")
    public Result delOrder(@PathVariable Integer id){
        log.info("{}",id);
        indentService.delOrder(id,request);
        return Result.success();
    }

}
